home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ML_BME1.ZIP / DISTORT / DISTASM.ASM < prev    next >
Encoding:
Assembly Source File  |  1996-11-04  |  7.2 KB  |  321 lines

  1. ; Distortion engine, v2.0
  2. ; by Maple Leaf, Nov 1996
  3. ; A crappy piece of unoptimized assembler...
  4. ; Do whatever you want with it... It isn't much useful, anyway :)))
  5. ;-**************************************************************************-
  6.  
  7. .model TPascal
  8. .386
  9.  
  10. .DATA
  11.  
  12.         extrn    Img:DWORD
  13.  
  14.         extrn    temp:WORD
  15.         extrn    vScr:WORD
  16.  
  17.         extrn    Wave1:WORD
  18.         extrn    Wave2:WORD
  19.         extrn    Wave3:WORD
  20.         extrn    Wave4:WORD
  21.  
  22.         extrn    SinTab:WORD
  23.         extrn    CosTab:WORD
  24.  
  25.         extrn    MaxAmplV:WORD  ; the real amplitude = MaxAmpl * 2 !!!!
  26.         extrn    MaxAmplH:WORD  ; the real amplitude = MaxAmpl * 2 !!!!
  27.         extrn    AngleIncrement:WORD  ; only bits 0-7 are used
  28.  
  29.  
  30.  
  31.  
  32. .CODE
  33.  
  34.         public   UpdateWaves
  35.         public   HoriDistort
  36.         public   VertDistort
  37.  
  38. include jumps.inc
  39.  
  40. ;-- some useful macros ------------------------------------------------------
  41.  
  42. LoadSin macro    factor
  43.         mov      di,bx
  44.         shl      di,factor
  45.         and      di,0FFh   ; is it correct ?
  46.         add      di,di
  47.         mov      cx,SinTab[di]
  48.         endm
  49.  
  50. LoadCos macro    factor
  51.         mov      di,bx
  52.         shl      di,factor
  53.         and      di,0FFh   ; is it correct ?
  54.         add      di,di
  55.         mov      cx,CosTab[di]
  56.         endm
  57.  
  58. Normalize macro
  59.         shrd     ax,dx,8
  60.         sar      dx,8   ; quite irrelevant
  61.         endm
  62.  
  63. uWaveH  macro    ofs
  64.         add      si,si
  65.         add      ax,MaxAmplH
  66.         mov      [si+ofs],ax
  67.         shr      si,1
  68.         endm
  69.  
  70. uWaveV  macro    ofs
  71.         add      si,si
  72.         add      ax,MaxAmplV
  73.         mov      [si+ofs],ax
  74.         shr      si,1
  75.         endm
  76.  
  77. ;--- don't laugh too loud of what follows :) --------------------------------
  78.  
  79. ang     dw       0
  80.  
  81. proc    UpdateWaves near
  82.  
  83.         mov      ax,AngleIncrement
  84.         add      cs:ang,ax
  85.         and      cs:ang,0FFh
  86.  
  87.         mov      cx,200
  88.         mov      si,0     ; k
  89.  
  90. @L1:    push     cx
  91.         mov      bx,si
  92.         add      bx,cs:ang   ; (k+ang)
  93.  
  94.         ; *** Wave1[] ***
  95.         mov      ax,MaxAmplH
  96.         LoadSin  1   ; cx:=sin((k+ang) shl 1)
  97.         imul     cx
  98.         Normalize
  99.         LoadCos  3   ; cx:=cos((k+ang) shl 3)
  100.         imul     cx
  101.         Normalize
  102.         uWaveH   Wave1
  103.  
  104.         ; *** Wave2[] ***
  105.         mov      ax,MaxAmplH
  106.         LoadCos  3   ; cx:=cos((k+ang) shl 3)
  107.         imul     cx
  108.         Normalize
  109.         LoadSin  2   ; cx:=sin((k+ang) shl 2)
  110.         imul     cx
  111.         Normalize
  112.         uWaveH   Wave2
  113.  
  114.         inc      si
  115.         pop      cx
  116.         dec      cx
  117.         jnz      @L1
  118.  
  119.         mov      cx,320
  120.         mov      si,0     ; k
  121.  
  122. @L2:    push     cx
  123.         mov      bx,si
  124.         add      bx,cs:ang   ; (k+ang)
  125.  
  126.         ; *** Wave3[] ***
  127.         mov      ax,MaxAmplV
  128.         LoadSin  3   ; cx:=sin((k+ang) shl 3)
  129.         imul     cx
  130.         Normalize
  131.         LoadSin  1   ; cx:=sin((k+ang) shl 1)
  132.         imul     cx
  133.         Normalize
  134.         uWaveV   Wave3
  135.  
  136.         ; *** Wave4[] ***
  137.         mov      ax,MaxAmplV
  138.         LoadCos  0   ; cx:=cos((k+ang) shl 1)
  139.         imul     cx
  140.         Normalize
  141.         LoadCos  3   ; cx:=cos((k+ang) shl 3)
  142.         imul     cx
  143.         Normalize
  144.         uWaveV   Wave4
  145.  
  146.         inc      si
  147.         pop      cx
  148.         dec      cx
  149.         jnz      @L2
  150.  
  151.         retn
  152. endp    UpdateWaves
  153.  
  154. ;--- horizontal distortion routine -----------------------------------------
  155.  
  156. fillGap macro    count
  157.         mov      cx,count
  158.         mov      al,0
  159.         rep      stosb
  160.         endm
  161.  
  162. counter1 dw      0
  163.  
  164. proc    HoriDistort near
  165.  
  166.         push     ds es fs
  167.         mov      di,0    ; Temp offset
  168.         mov      si,0    ; Img offset
  169.  
  170.         mov      cx,200
  171.  
  172.         push     ds
  173.         pop      fs
  174.         mov      es,Temp
  175.         mov      ds,Img[2]
  176.  
  177.         mov      bx,0  ; line no. (k)
  178.  
  179. @HDL:   push     bx cx
  180.         mov      si,bx
  181.         add      bx,bx
  182.  
  183.         assume fs:DATA
  184.         fillGap  fs:Wave1[bx]       ; LEFT black area size
  185.  
  186.         mov      ecx,319
  187.         sub      cx,fs:Wave2[bx]
  188.         sub      cx,fs:Wave1[bx]
  189.         inc      cx        ; cx = NewXSize
  190.         mov      eax,1400000h  ; 320 * 65536
  191.         xor      edx,edx
  192.         div      ecx
  193.         mov      word ptr cs:smc1+5,ax
  194.         shr      eax,16
  195.         mov      word ptr cs:smc2+2,ax
  196.  
  197.         mov      cs:counter1,0
  198.         mov      dx,si
  199.         shl      si,6
  200.         shl      dx,8
  201.         add      si,dx  ; k*320
  202.  
  203. @@L3:   mov      al,[si]
  204.         stosb
  205. smc1:   add      cs:counter1,1234h
  206. smc2:   adc      si,1234h
  207.         dec      cx
  208.         sjnz     @@L3
  209.  
  210.         fillGap  fs:Wave2[bx]       ; RIGHT black area size
  211.  
  212.         pop      cx bx
  213.         inc      bx
  214.         dec      cx
  215.         sjnz     @HDL
  216.  
  217.         pop      fs es ds
  218.  
  219.         retn
  220. endp    HoriDistort
  221.  
  222. ;--- vertical distortion routine --------------------------------------------
  223.  
  224. StoreByte macro
  225.         mov      es:[di],al
  226.         add      di,320
  227.         endm
  228.  
  229. fillGap2 macro   count
  230.         local    @LA1, @SLA1
  231.         mov      cx,count
  232.         sjcxz    @@SLA1
  233.         mov      al,0
  234. @@LA1:  StoreByte
  235.         dec      cx
  236.         sjnz     @@LA1  ; draw it
  237. @@SLA1: endm
  238.  
  239. fillGap3 macro   count
  240.         local    @LA2, @SLA2
  241.         mov      cx,count
  242.         sjcxz    @@SLA2
  243.         mov      al,0
  244. @@LA2:  StoreByte
  245.         dec      cx
  246.         sjnz     @@LA2  ; draw it
  247. @@SLA2:
  248.         endm
  249.  
  250. proc    VertDistort near
  251.  
  252.         push     ds es fs
  253.         mov      di,0    ; vScr offset
  254.         mov      si,0    ; Temp offset
  255.  
  256.         mov      cx,320
  257.  
  258.         push     ds
  259.         pop      fs
  260.         mov      es,vScr
  261.         mov      ds,Temp
  262.  
  263.         mov      bx,0  ; col no. (k)
  264.  
  265. @VDL:   push     bx cx
  266.         mov      di,bx
  267.         mov      si,bx
  268.         add      bx,bx
  269.  
  270.         assume   fs:DATA
  271.         fillGap2 fs:Wave3[bx]   ; TOP black area size
  272.  
  273.         mov      ecx,199
  274.         sub      cx,fs:Wave4[bx]
  275.         sub      cx,fs:Wave3[bx]
  276.         inc      cx        ; cx = NewYSize
  277.         mov      eax,0C80000h  ; (200 * 65536)
  278.         xor      edx,edx
  279.         div      ecx    ; eax=(200/NewYsize) * 65536
  280.  
  281.         mov      word ptr cs:smc3+5,ax   ;
  282.         shr      eax,16                  ; SMCODE init
  283.         mov      word ptr cs:smc4+2,ax   ;
  284.  
  285.         mov      cs:counter1,0
  286.         mov      dx,0
  287.  
  288.         push     bx
  289.         mov      word ptr cs:smc5+2,si
  290.  
  291. @@C4:   mov      al,[si]
  292.         StoreByte
  293. smc3:   add      cs:counter1,1234h
  294. smc4:   adc      dx,1234h
  295.  
  296.         mov      bx,dx       ;  ughhh, shit !  these take a lot of useful
  297.         mov      si,bx       ;  time !
  298.         shl      bx,6        ;  is there any other choice ?
  299.         shl      si,8        ;
  300.         add      si,bx       ;
  301. smc5:   add      si,1234h    ;
  302.  
  303.         dec      cx
  304.         sjnz     @@C4
  305.         pop      bx
  306.  
  307.         fillGap3 fs:Wave4[bx]   ; BOTTOM black area size
  308.  
  309.         pop      cx bx
  310.         inc      bx
  311.         dec      cx
  312.         jnz      @VDL
  313.  
  314.         pop      fs es ds
  315.  
  316.         retn
  317. endp    VertDistort
  318.  
  319.         END
  320.  
  321.         ; hhrrrrrr...